package com.example.john.myapplication;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class UserParser {
    public static List<User> parseUsers(String json) {
       List<User> users=new ArrayList<User>();
        try {
            JSONArray jsa=new JSONArray(json);
            for (int i = 0; i < jsa.length(); i++) {
                JSONObject jso=(JSONObject) jsa.get(i);
                User u=new User(jso.getInt("id"),jso.getString("name"),jso.getInt("age"));
                users.add(u);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return users;
    }

}
